import java.util.HashMap;

public class FlyweightFactory {
    public FlyweightFactory() {
    }

    //池子
    private HashMap<String ,Flyweight> flyweights=new HashMap<String ,Flyweight>();

    public Flyweight getFlyweight(String key){
        Flyweight returnFlyweight;
        if(flyweights.containsKey(key)){
            returnFlyweight =flyweights.get(key);
        }else{
            Flyweight newFlyweight = new ConcreteFlyweight(key);
            flyweights.put(key,newFlyweight);
            returnFlyweight=newFlyweight;
        }
        return returnFlyweight;
    }
}
